var app = getApp()
Page({
	data: {
    orders:[]
  },
  deleteOrder: function (e) {
    var self = this;
    console.log(e.target.dataset.id);
    if (1 == e.target.dataset.status){
      wx.showModal({
        title: '提示',
        content: '订单派送中，不可删除',
        showCancel: false
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '您将删除该订单记录，不可恢复',
        success: function (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            wx.request({
              url: app.globalData.serverAddress + '/order/apis/delOrderById',
              data: {
                id: e.target.dataset.id
              },
              header: {
                'content-type': 'application/json' // 默认值
              },
              success: function (res) {
                console.log(res.data);
                wx.showModal({
                  title: '提示',
                  content: '删除成功',
                  showCancel: false,
                  success: function (res) {
                    self.onLoad();
                  }
                })
              }
            });
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
  },
  onLoad: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    wx.request({
      url: app.globalData.serverAddress + '/order/apis/getallorder',
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        wx.hideLoading();
        console.log(res.data);
        that.setData({
          orders: res.data
        });
      }
    });
  },
  onShow: function () { },
  onPullDownRefresh: function () {
    this.onLoad();
    wx.stopPullDownRefresh();
  }
});

